<?php
namespace app\common\model\blfyy;
use app\common\model\BaseModel;
use think\Db;
use chrome\ChromePhp;//引入chromephp插件
use common\Common;//公共函数

/**
 * 提供音乐平台管理服务
 * @name LibMusic.php
 * @package blfyy
 * @category model
 * @link http://www.chanekeji.com
 * @author syben
 * @version 1.0
 * @copyright CHANGE INC
 * @since 2021-03-11
 */
class LibMusic extends BaseModel{
	protected $m_music;

	/**
	 * 构造函数
	 */
	public function __construct(){
		$this->m_music = db('music_platform');
		parent::__construct();
	}
	
	/**
	 * 添加音乐平台信息
	 */
	public function addMusic($condition){
		try {
			$condition['add_time'] = Common::getTime();
			$reslut = $this->m_music->insertGetId($condition);		
			if(true == $reslut){
				return Common::errorArray(0, "添加成功",$reslut);
			}else{
				return Common::errorArray(1, "添加失败", $reslut);
			}
		}catch (Exception $ex){
			$this->errorLog(__CLASS__, __FUNCTION__, $ex);
			return  Common::errorArray(1, "数据库操作失败", $ex);
		}
	}
	
	
	
	/**
	 * 查询单个音乐平台信息
	 * @param $condition
	 * @param array $result
	 */
	public function findMusic($condition='',$field=''){		
		try {
			$reslut = $this->m_music->where($condition)->field($field)->find();	
					
			if(true == $reslut){
				return Common::errorArray(0, "查询成功",$reslut);
			}else{
				return Common::errorArray(1, "查询为空", $reslut);
			}
		}catch (Exception $ex){
			$this->errorLog(__CLASS__, __FUNCTION__, $ex);
			return  Common::errorArray(1, "数据库操作失败", $ex);
		}
	}
	
	/**
	 * 查询多个音乐平台信息
	 * @param $condition
	 * @param $limit
	 * @param $field
	 * @param $sort
	 * @param array $result
	 */
	public function findAllMusic($condition='',$limit='',$field='',$sort='add_time desc'){		
		try {
			$reslut = $this->m_music->where($condition)->order($sort)->limit($limit)->field($field)->select();			
			if(true == $reslut){
				return Common::errorArray(0, "查询成功",$reslut);
			}else{
				return Common::errorArray(1, "查询为空", $reslut);
			}
		}catch (Exception $ex){
			$this->errorLog(__CLASS__, __FUNCTION__, $ex);
			return  Common::errorArray(1, "数据库操作失败", $ex);
		}
	}
	
	/**
	 * 更新音乐平台信息
	 * @param $condition
	 * @param $userInfo
	 * @param array $result
	 */
	public function updateMusic($condition,$userInfo){
		try {
			$reslut = $this->m_music->where($condition)->update($userInfo);	
			if($reslut >= 0){
				return Common::errorArray(0, "更新成功",$reslut);
			}else{
				return Common::errorArray(1, "更新失败", $reslut);
			}
		}catch (Exception $ex){
			$this->errorLog(__CLASS__, __FUNCTION__, $ex);
			return  Common::errorArray(1, "数据库操作失败", $ex);
		}
	}
	
	/**
	 * 删除音乐平台信息
	 * @param $condition
	 * @param array $result
	 */
	public function deleteMusic($ids){
		$condition = array('id'=>array('in',$ids));
		try {
			$reslut = $this->m_music->where($condition)->delete();;		
			if($reslut > 0){
				return Common::errorArray(0, "删除成功",$reslut);
			}else{
				return Common::errorArray(1, "删除失败", $reslut);
			}
		}catch (Exception $ex){
			$this->errorLog(__CLASS__, __FUNCTION__, $ex);
			return  Common::errorArray(1, "数据库操作失败", $ex);
		}
	}
	
	/**
	 * 字段值加1
	 * @param $condition
	 * @param string $field
	 * @param int $optval
	 * @param array $reslut
	 */
	public function increaseField($condition,$field,$optval = 1){
		try {
			$reslut = $this->m_music->where($condition)->setInc($field,$optval);;		
			if(true == $reslut){
				return Common::errorArray(0, "修改成功",$reslut);
			}else{
				return Common::errorArray(1, "修改失败", $reslut);
			}
		}catch (Exception $ex){
			$this->errorLog(__CLASS__, __FUNCTION__, $ex);
			return  Common::errorArray(1, "数据库操作失败", $ex);
		}
	}
	
	/**
	 * 字段值减1
	 * @param $condition
	 * @param string $field
	 * @param int $optval
	 * @param array $reslut
	 */
	public function decreaseField($condition,$field,$optval = 1){
		try {
			$reslut = $this->m_music->where($condition)->setDec($field,$optval);;		
			if(true == $reslut){
				return Common::errorArray(0, "修改成功",$reslut);
			}else{
				return Common::errorArray(1, "修改失败", $reslut);
			}
		}catch (Exception $ex){
			$this->errorLog(__CLASS__, __FUNCTION__, $ex);
			return  Common::errorArray(1, "数据库操作失败", $ex);
		}
	}
	
	/**
	 * 分页获取数据音乐平台信息
	 */
	public function pagingMusic($page,$conditionList,$sort = '',$orList = null){
		$reslut = Common::paging('music_platform',$page,$conditionList,$sort,$orList);
		return  $reslut;  		
	}
	
}


?>